package com.test.day04.reader;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @program: 用try catch对流的异常进行处理
 * @author: luhd
 * @create: 2021-08-07
 */
public class Demo05Exception {
    public static void main(String[] args) {
        FileWriter fw = null;
        try{
            fw = new FileWriter("e.txt",true);
            for (int i = 0; i < 10; i++) {
                fw.write("helloworld"+i+"\r\n");
            }
        }catch (IOException e){
            System.out.println(e);
        }finally {
            try {
                //fw.close()方法声明抛出了IOException异常对象，所以要么throws，要么try catch
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
